package com.zhb.delayQueue.schedule;

import com.zhb.delayQueue.common.ThreadFactoryImpl;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by millions on 2017/1/10.
 * 配置轮询服务
 */
@SpringBootConfiguration
public class ScheduleConfig {
    /**
     * 返回轮询delay bucket的任务
     *
     * @return ExecutorService
     */
    @Bean
    public ScheduledExecutorService schedulePollingService() {
        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("delay-polling-thread"));
        executorService.scheduleAtFixedRate(new DelayPollTask(), 5000, 100, TimeUnit.MILLISECONDS);
        return executorService;
    }
}
